$containerSize: 300px;
$dotSize: 20px;
$n: 36;
$pdeg: calc(360deg / $n);
$animation-delay: 2s;

.loading {
  width: $containerSize;
  height: $containerSize;
  border-radius: 50%;
  position: relative;
}
.dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: $dotSize;
  height: $dotSize;
  margin-left: calc(-1 * $dotSize / 2);
  margin-top: calc(-1 * $dotSize / 2);
  perspective: 70px; // 元素距视图的距离  https://www.w3school.com.cn/cssref/pr_perspective.asp
  transform-style: preserve-3d;
  &::after, &::before{
    content: '';
    position: absolute;
    height: 100%;
    width: 100%;
    border-radius: 50%;
  }

  &::before {
    background-color: black;
    top: -100%;
    animation: moveBlack $animation-delay infinite;
  }
  
  &::after {
    background-color: white;
    top: 100%;
    animation: moveWhite $animation-delay infinite;
  }
}

@keyframes moveBlack {
  0% {
    animation-timing-function: ease-in;
  }
  25% {
    transform: translate3d(0, 100%, $dotSize);
    animation-timing-function: ease-out;
  }
  
  50% {
    transform: translate3d(0, 200%, 0);
    animation-timing-function: ease-in;
  }
  
  75% {
    transform: translate3d(0, 100%, -$dotSize);
    animation-timing-function: ease-out;
  }
}

@keyframes moveWhite {
  0% {
    animation-timing-function: ease-in;
  }
  25% {
    transform: translate3d(0, -100%, -$dotSize);
    animation-timing-function: ease-out;
  }

  50% {
    transform: translate3d(0, -200%, 0);
    animation-timing-function: ease-in;
  }

  75% {
    transform: translate3d(0, -100%, $dotSize);
    animation-timing-function: ease-out;

  }
}

@for $i from 1 through $n {
  .dot:nth-child(#{$i}) {
    transform: rotate(15deg * $i) translateY(calc(-1 * $containerSize / 2));
    &::after, &::before{
      animation-delay: calc(-1 * $animation-delay / $n * 6 * $i)
    }
  }
}
